package com.ry.core.base.dao.mybatis;

import java.util.List;
import java.util.Map;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.dao.DataAccessException;

import com.ry.core.base.model.SimpleModel;

/**
 * mybatis接口默认实现类
 * 
 * @author lqw
 * 
 */
public class BatisDaoImpl implements BatisDao {

	public SqlSessionTemplate sqlSession;

	@SuppressWarnings("unchecked")
	@Override
	public List<SimpleModel> findListByMap(String nameSpace,
			Map<String, Object> m) throws DataAccessException {
		return (List<SimpleModel>) sqlSession.selectList(nameSpace
				+ ".findListByMap", m);
	}

	@Override
	public SimpleModel get(String nameSpace, String id)
			throws DataAccessException {
		return (SimpleModel) sqlSession.selectOne(nameSpace + ".get", id);
	}

	@Override
	public int selectCount(String nameSpace, Map<String, Object> m)
			throws DataAccessException {
		return Integer.parseInt(sqlSession.selectOne(
				nameSpace + ".selectCount", m).toString());
	}

	@Override
	public List<?> getList(String nameSpace) throws DataAccessException {
		return sqlSession.selectList(nameSpace + ".getList");
	}

	public void setSqlSession(SqlSessionTemplate sqlSession) {
		this.sqlSession = sqlSession;
	}

	public SqlSessionTemplate getSqlSession() {
		return sqlSession;
	}

}
